<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    年：<input type="text" id="year">
    月：<input type="text" id="month">
    日：<input type="text" id="day">
    <button id="btn">判断</button>
    <input type="text" id="result">
</body>
<script>
    var yearInp = document.getElementById("year");
    var monthInp = document.getElementById("month");
    var dayInp = document.getElementById("day");
    var btn = document.getElementById("btn");
    var resultInp = document.getElementById("result");

    // console.log(yearInp, monthInp, dayInp, btn, resultInp);

    btn.onclick = function () {
        // alert(1111111);
        var year = yearInp.value * 1;
        var month = monthInp.value * 1;
        var day = dayInp.value * 1;
        console.log(year,month,day);

        // 年份  1000-4000  整数
        if (year >= 1000 && year <= 4000 && year % 1 == 0) {
            // resultInp.value = "年份正确";
            // 月份  1-12
            if (month >= 1 && month <= 12 && month % 1 == 0) {
                resultInp.value = "月份正确";
                var maxDay = 0;

                //日期   (1,3,5,7,8,10,12=>31)  (4,6,9,11 =>30)  (2=> 28/29);
                // if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {//(1,3,5,7,8,10,12=>31)
                //     maxDay = 31;

                // } else if (month == 4 || month == 6 || month == 9 || month == 11) {//(4,6,9,11 =>30)
                //     maxDay = 30;

                // } else {
                //     //    2 月  先判断平年还是闰年
                //     if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {//闰年=>29
                //         maxDay = 29;
                //     } else {//平年  =》28
                //         maxDay = 28;
                //     }

                // }
                switch (month){
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12:maxDay=31;
                    break;
                    case 4:
                    case 6:
                    case 9:
                    case 11:maxDay=30;
                    break;
                    default:
                    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                        maxDay = 29;
                    } 
                    else {
                        maxDay = 28;
                    }
                }

                console.log(maxDay);  //提出公的的maxDay
                if (day >= 1 && day <= maxDay && day % 1 == 0) {
                    resultInp.value = "日期正确";

                } else {
                    resultInp.value = "日期错误";
                }
            } else {
                resultInp.value = "月份错误";
            }
        } else {
            resultInp.value = "年份错误";
        }
   }

    // "" null,0,NaN, undefined
    // if (1 || 3 | 5) {
    //     console.log(333333333);
    // } else {
    //     console.log("00000000000")
    // }

</script>

</html>